﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    public class UserBussiness:IDbServices<bool, int, TblUser>
    {
        BookingDB db = new BookingDB();

        public bool AddData(TblUser e)
        {
            try
            {

                db.TblUsers.Add(e);
                db.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return false;
            }


        }

        public bool UpdateData(TblUser e)
        {
            try
            {

                db.Entry(e).State = EntityState.Modified;
                db.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {

                return false;
            }
        }

        public bool DeleteData(int key)
        {
            TblUser objRoomType = new TblUser();
            objRoomType = db.TblUsers.Find(key);
            try
            {
                db.TblUsers.Remove(objRoomType);
                db.SaveChanges();
                return true;

            }
            catch (Exception ex)
            {
                return false;
            }

        }

        public TblUser  GetDataByKey(int k)
        {
            try
            {
                return db.TblUsers.Find(k);
            }
            catch (Exception)
            {

                return null;
            }
        }

        public List<TblUser> GetAll()
        {
            try
            {
                return db.TblUsers.ToList<TblUser>();
            }
            catch (Exception e)
            {

                return null;
            }
        }

        public List<TblUser> GetAllDataByPosition(int k)
        {
            var temp = db.TblUsers.Where(b => b.Positions == k);
            return temp.ToList<TblUser>();
        }
    }
}
